<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
        <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
        <title>随手快递</title>
        <link rel="stylesheet" type="text/css" href="../../AUI/css/aui.css" />
        <link rel="stylesheet" type="text/css" href="../../font-awesome/css/font-awesome.min.css" />
        <style type="text/css">
            .st-v{
                border: 1px solid rgba(214, 228, 167, 0.58);
                background: rgba(214, 228, 167, 0.58);
                border-radius: 10px;
                margin: 0px 15px 15px 15px;
            }
            .st-m{
                border-left:2px dotted #bfcb94;
                height: 100%;
                padding:16px 0 0 0px;
                text-align: center;
                width: 40px;
            }
            .aui-padded-15{
                padding-right: 10px !important;
            }
        </style>
    </head>
    <body style="overflow-x: hidden">
        <header class="aui-bar aui-bar-nav" id="aui-header">
            <a class="aui-btn aui-pull-left" tapmode onclick="history.back();">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title">代金券</div>
            <div class="aui-btn aui-pull-right"></div>
        </header>
        <div class="aui-content" style="margin-top: 50px;background: rgba(253, 253, 253, 0.95);padding: 15px 0 1px 0">
            <div id="voucher"></div>
            <div style="float:right;width:100%;background:#fff;padding: 10px 20px;color: #0a628f" onclick="location.href='change_vouchar.html'"><span style="float: right">兑换代金券 <span class="fa fa-chevron-right"></span></span></div>

        </div>

        <script src="../../myJs/jquery.js"></script>
    <script>
       /*  var data={
            "code": 95158,
            "msg": [
                {
                    "vouchersId": 1,
                    "vouchersName": "抵用券-新用户专享",
                    "vouchersFailuretime": "有效期至2017-8-30",
                    "vouchersPrice": "10",
                    "vouchersScore": 15060
                },
                {
                    "vouchersId": 2,
                    "vouchersName": "抵用券-通用",
                    "vouchersFailuretime": "有效期至2017-8-30",
                    "vouchersPrice": "5",
                    "vouchersScore": 3
                },
                {
                    "vouchersId": 4,
                    "vouchersName": "抵用券-通用",
                    "vouchersFailuretime": "有效期至2017-8-30",
                    "vouchersPrice": "5",
                    "vouchersScore": 64704
                }
            ]
        } */

        $(function() {
             $.ajax({
             type: "post",
             url: '/randomdelivery/userWalletManageController/lookOwnVouchers',
             data: { },
             datatype: "json",
             success: function (data) {
            	 alert(JSON.stringify(data));
            	 viewVoucher(data);
             }
             });
            
        })

        function viewVoucher(data){
            var data = data.msg;
            $.each(data,function(num,data){
                $("#voucher").append(' <div class="aui-list st-v" onclick="useVoucher(this)" userVouchersId="'+data.userVouchersId+'">\
                        <div class="aui-list-item">\
                        <div class="aui-list-item-inner aui-padded-15">\
                        <div class="aui-list-item-title">\
                        <h3 class="aui-padded-b-5">'+data.vouchersName+'</h3><small style="color: #626262">'+data.vouchersFailuretime+'</small></div>\
                        <div class="st-m">￥'+data.vouchersPrice+'</div>\
                        </div>\
                        </div>\
                        </div>');
            })

        }

        function useVoucher(node){
        	var orderId = sessionStorage.getItem("orderId");
        	alert(orderId);
            var userVouchersId = node.getAttribute("userVouchersId");
            //alert(vouchersId);
                     $.ajax({
             type: "post",
             url: '/randomdelivery/userDemandController/payPricePageVoucher',
             data: {
            	 orderId:orderId,
            	 userVouchersId:userVouchersId
             },
             datatype: "json",
             success: function (data) {
            	 alert(JSON.stringify(data));
            	 location.href='../helpMe/pay.html';
             }
             });
           
        }

    </script>
    </body>
</html>